home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Shareware Grab Bag
/
Shareware Grab Bag.iso
/
001
/
pibt3sp3.arc
/
RECEIVEM.PAS
< prev
next >
Wrap
Pascal/Delphi Source File
|
1985-10-05
|
10KB
|
263 lines
(*----------------------------------------------------------------------*)
(* Receive_Modem7_File --- Download file with Modem7/Telink *)
(*----------------------------------------------------------------------*)
PROCEDURE Receive_Modem7_File( Use_CRC: BOOLEAN );
(*----------------------------------------------------------------------*)
(* *)
(* Procedure: Receive_Modem7_File *)
(* *)
(* Purpose: Downloads file to PC using Modem7/Telink batch *)
(* *)
(* Calling Sequence: *)
(* *)
(* Receive_Modem7_File( Use_CRC : BOOLEAN); *)
(* *)
(* Use_CRC --- TRUE to use CRC checking; *)
(* FALSE to use checksum checking. *)
(* *)
(* Calls: KeyPressed *)
(* Async_Send *)
(* Async_Receive *)
(* Receive_Xmodem_File *)
(* *)
(* Remarks: *)
(* *)
(* This routine performs the "echo file name" function of *)
(* Modem7, required by batch Modem7 and Telink. *)
(* *)
(*----------------------------------------------------------------------*)
CONST
MaxTry = 5;
MaxNoise = 10;
VAR
RFileName : AnyStr;
Int_Ch : INTEGER;
Int_Ch_Save : INTEGER;
Ch : CHAR;
CheckSum : INTEGER;
EndFName : BOOLEAN;
I : INTEGER;
Local_Save : Saved_Screen_Ptr;
Tname : STRING[10];
Tries : INTEGER;
NTries : INTEGER;
Batch_Title : AnyStr;
(*----------------------------------------------------------------------*)
(* Check_KeyBoard --- Check for keyboard input *)
(*----------------------------------------------------------------------*)
PROCEDURE Check_KeyBoard;
BEGIN (* Check_KeyBoard *)
(* If Alt_R found, stop transfer *)
IF KeyPressed THEN
BEGIN
READ( Kbd, Ch );
IF ( Ch = CHR( ESC ) ) AND KeyPressed THEN
BEGIN
READ( Kbd, Ch );
IF ORD( Ch ) = Alt_R THEN
BEGIN
Stop_Receive := TRUE;
WRITELN(' Alt_R accepted, transfer cancelled.');
END;
END;
END;
END (* Check_KeyBoard *);
(*----------------------------------------------------------------------*)
BEGIN (* Receive_Modem7_File *)
(* Open display window for transfers *)
Save_Screen( Local_Save );
CASE Transfer_Protocol OF
Telink : Tname := 'Telink';
Modem7_Chk : Tname := 'Modem7 (Checksum)';
Modem7_CRC : Tname := 'Modem7 (CRC)';
END (* CASE *);
(* Telink is always CRC mode *)
Use_CRC := Use_CRC OR ( Transfer_Protocol = Telink );
Batch_Title := 'Batch file download using ' + Tname;
Draw_Menu_Frame( 2, 2, 79, 24, Menu_Frame_Color,
Menu_Text_Color, Batch_Title );
Writelne( Batch_Title , FALSE );
Window( 3, 3, 78, 23 );
(* Flag if keyboard halt or EOT *)
(* encountered *)
Stop_Receive := FALSE;
(* Purge reception to remove noise *)
Async_Purge_Buffer;
(* Loop over file names *)
REPEAT
(* Initialize checksum *)
CheckSum := 0;
(* Initialize file name *)
RFileName := '';
(* Try up to MaxTry times to *)
(* send NAK to say we're ready *)
(* for the file name. *)
REPEAT
(* Send NAK *)
Async_Send( CHR( NAK ) );
(* Get response -- should be ACK *)
(* NOTE: skip up to MaxNoise chars *)
(* that are clearly garbage *)
(* in effort to get ACK *)
NTries := 0;
REPEAT
Async_Receive_With_TimeOut( Two_Seconds , Int_Ch );
NTries := NTries + 1;
Check_Keyboard;
UNTIL ( Ntries > MaxNoise ) OR
( Int_Ch <= 127 ) OR
Stop_Receive;
Tries := Tries + 1;
UNTIL( Int_Ch = ACK ) OR
( Int_Ch = EOT ) OR
( Int_Ch = CAN ) OR
( Tries > MaxTry ) OR
Stop_Receive;
(* Only continue if ACK found *)
Stop_Receive := ( Int_Ch <> ACK ) OR Stop_Receive;
Int_Ch_Save := Int_Ch;
(* Pick up characters of file name *)
IF ( NOT Stop_Receive ) THEN
REPEAT
Async_Receive_With_TimeOut( Five_Seconds , Int_Ch );
Check_KeyBoard;
EndFName := ( Int_Ch = CAN ) OR
( Int_Ch = EOT ) OR
( Int_Ch = TimeOut ) OR
( Int_Ch = SUB ) OR
Stop_Receive;
IF ( NOT EndFname ) THEN
BEGIN
Async_Send( CHR( ACK ) ); (* echo 1 char at a time *)
RFileName := RFileName + CHR( Int_Ch );
Checksum := ( Checksum + Int_Ch ) AND 255;
END;
UNTIL EndFname
ELSE
Int_Ch := TimeOut;
(* Finished getting filename. *)
IF ( Int_Ch = SUB ) THEN
BEGIN (* Filename received *)
(* Send checksum *)
CheckSum := ( CheckSum + Int_Ch ) AND 255;
Async_Send( CHR( CheckSum ) );
(* Get response to checksum *)
Async_Receive_With_TimeOut( Five_Seconds , Int_Ch );
Check_KeyBoard;
(* If checksum OK, do transfer *)
IF ( Int_Ch = ACK ) AND ( NOT Stop_Receive ) THEN
BEGIN
FOR I := LENGTH( RFileName ) TO 11 DO
RFileName := RFileName + ' ';
FileName := Trim( COPY( RFileName, 1, 8 ) );
IF COPY( RfileName, 9, 3 ) <> ' ' THEN
FileName := FileName + '.' + COPY( RFileName, 9, 3 );
(* Prevent overwrite of host mode *)
(* files. *)
IF Host_Mode THEN
Stop_Receive := Stop_Receive OR
Scan_Xfer_List( FileName ) OR
( FileName = 'PIBTERM.USF' ) OR
( FileName = 'PIBTERM.XFR' ) OR
( FileName = 'PIBTERM.MSG' ) OR
( FileName = 'PIBTERM.CMT' ) OR
( FileName = 'PIBTERM.CMT' );
(* Get the file. *)
IF ( NOT Stop_Receive ) THEN
BEGIN
Writelne(' Downloading: ' + FileName , TRUE );
Receive_Xmodem_File( Use_CRC );
TextColor( Menu_Text_Color );
END;
END
ELSE
Stop_Receive := TRUE;
END (* Filename received *)
ELSE
Stop_Receive := TRUE;
UNTIL Stop_Receive;
(* Acknowledge EOT if received *)
IF ( Int_Ch_Save = EOT ) THEN
BEGIN
Async_Send( CHR( ACK ) );
Writelne(' ', TRUE);
Writelne(' Received EOT from host.' , TRUE );
END
ELSE
BEGIN
Writelne( ' ' , TRUE );
Writelne( ' Transfer cancelled.' , TRUE );
END;
(* Indicate end of transfer *)
Writelne(' ', TRUE);
RvsVideoOn ( Menu_Text_Color, BackGround_Color );
Writelne(' Batch transfer complete.', TRUE);
RvsVideoOff( Menu_Text_Color, BackGround_Color );
DELAY( Two_Second_Delay );
(* Remove batch transfer window *)
Restore_Screen( Local_Save );
Reset_Global_Colors;
END (* Receive_Modem7_File *);